package com.ruibang.glass.produce.component.job;

import com.ruibang.glass.produce.domain.req.Cold1DispatchReq;
import com.ruibang.glass.produce.entity.Cold1Dispatch;
import com.ruibang.glass.produce.service.Cold1DispatchService;
import com.teaming.cloud.framework2.elastic.job3.annotation.ElasticJobScheduler;
import lombok.extern.slf4j.Slf4j;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.simple.job.SimpleJob;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * @Author: songJinKang
 * @CreateTime: 2024-06-06  14:18
 * @Description: TODO:冷端一号线调度数据任务
 * @Version: 1.0
 */
@Slf4j
@ElasticJobScheduler(cron = "6 6 0/1 * * ?")
//@ElasticJobScheduler(cron = "0 * * * * ?")
@Component
public class Cold1DispatchDataTask implements SimpleJob {

    @Autowired
    private Cold1DispatchService cold1DispatchService;

    @Override
    public void execute(ShardingContext shardingContext) {
        LocalDateTime end = LocalDateTime.now();
        LocalDateTime start = end.minusHours(1);
        LocalDateTime endTime = LocalDateTime.of(end.getYear(), end.getMonthValue(), end.getDayOfMonth(), end.getHour(), 0, 0);
        LocalDateTime startTime = LocalDateTime.of(start.getYear(), start.getMonthValue(), start.getDayOfMonth(), start.getHour(), 0, 0);
        Cold1DispatchReq cold1DispatchReq = new Cold1DispatchReq();
        cold1DispatchReq.setStartTime(startTime);
        cold1DispatchReq.setEndTime(endTime);
        Cold1Dispatch cold1Dispatch = cold1DispatchService.executeTask(cold1DispatchReq);
        cold1Dispatch.setCollectTime(startTime);
        cold1DispatchService.save(cold1Dispatch);
    }

}
